<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>load_register</title>
    <link rel="stylesheet" href="css/index.css">
    <script src="lib/jquery-3.1.1.min.js"></script>
    <script src="app/index.js"></script>
</head>
<body>

    <div class="load_register_box">
        <div class="load_register_header">登录</div>
        <form action="" method="post" id="documentForm">
            <ul class="input-box">
                <li><input type="text" name="phone" placeholder="用户名" id="loadUser"></li>
                <li><input type="password" name="password" placeholder="密码" id="loadPassword"></li>
                <li><button type="button" id="load">登录</button></li>
            </ul>
        </form>
    </div>
    <div class="load-info"></div>

</body>
</html>
<script>
    var commonUrl = 'http://172.30.31.254:8080/youhuishop/';
    var $loadInfo = $('.load-info');

    $('#load').on('click',function () {
        var $username = $('#loadUser').val();
        var $password = $('#loadPassword').val();
        if($username == ""){
            setTimeout(function () {
                $loadInfo
                    .text("用户名不能为空！")
                    .fadeIn(500);
            },500);
            return false;
        }
        if($password == ""){
            setTimeout(function () {
                $loadInfo
                    .text("密码不能为空！")
                    .fadeIn(500);
            },500);
            return false;
        }
            $.ajax({
                url:commonUrl + 'api/user/login',
                type:'POST',
                dataType:'json',
                data:{
                    phone:$username,
                    password:$password
                },
                success:function (data) {
                    console.log('获取成功');
                    if(data.success){
                        console.log(data);
                        window.localStorage.setItem('sid',data.data);
                        setTimeout(function () {
                            $loadInfo
                                .text(data.info)
                                .fadeIn(500,function () {
                                    window.location.href = 'index.html';
                                });

                        },500);
                    }else{
                        console.log(data);
                        setTimeout(function () {
                            $loadInfo
                                .text(data.info)
                                .fadeIn(500);
                        },500);
                    }
                },
                error:function (err) {
                    console.log('获取失败');
                    console.log(err);
                }
            })

    });
    $('#loadUser').on('focus',function () {
        $loadInfo.hide();
    });
    $('#loadPassword').on('focus',function () {
        $loadInfo.hide();
    })


</script>